 

package com.zdkj.subway.stm.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.service.PigxUser;
import com.zdkj.common.security.util.SecurityUtils;
import com.zdkj.subway.stm.entity.SwStInvoiceXaztCheck;
import com.zdkj.subway.stm.enums.InvoiceChechAuditTypeEnum;
import com.zdkj.subway.stm.service.SwStInvoiceXaztCheckService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 西安中铁定额发票盘点
 *
 * @author cxp
 * @date 2024-11-27 20:05:26
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swstinvoicexaztcheck" )
@Api(value = "swstinvoicexaztcheck", tags = "西安中铁定额发票盘点管理")
public class SwStInvoiceXaztCheckController {

    private final  SwStInvoiceXaztCheckService swStInvoiceXaztCheckService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param swStInvoiceXaztCheck 西安中铁定额发票盘点
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    public R getSwStInvoiceXaztCheckPage(Page page, SwStInvoiceXaztCheck swStInvoiceXaztCheck) {
		
		return R.ok(swStInvoiceXaztCheckService.page(page, swStInvoiceXaztCheck));
    }


    /**
     * 通过id查询西安中铁定额发票盘点
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(swStInvoiceXaztCheckService.getById(id));
    }

    /**
     * 新增西安中铁定额发票盘点
     * @param swStInvoiceXaztCheck 西安中铁定额发票盘点
     * @return R
     */
    @ApiOperation(value = "新增西安中铁定额发票盘点", notes = "新增西安中铁定额发票盘点")
    @SysLog("新增西安中铁定额发票盘点" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('stm_swstinvoicexaztcheck_add')" )
    public R save(@RequestBody SwStInvoiceXaztCheck swStInvoiceXaztCheck) {
        return R.ok(swStInvoiceXaztCheckService.save(swStInvoiceXaztCheck));
    }

    /**
     * 修改西安中铁定额发票盘点
     * @param swStInvoiceXaztCheck 西安中铁定额发票盘点
     * @return R
     */
    @ApiOperation(value = "修改西安中铁定额发票盘点", notes = "修改西安中铁定额发票盘点")
    @SysLog("修改西安中铁定额发票盘点" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('stm_swstinvoicexaztcheck_edit')" )
    public R updateById(@RequestBody SwStInvoiceXaztCheck swStInvoiceXaztCheck) {
        return R.ok(swStInvoiceXaztCheckService.updateById(swStInvoiceXaztCheck));
    }

    /**
     * 通过id删除西安中铁定额发票盘点
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除西安中铁定额发票盘点", notes = "通过id删除西安中铁定额发票盘点")
    @SysLog("通过id删除西安中铁定额发票盘点" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('stm_swstinvoicexaztcheck_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(swStInvoiceXaztCheckService.removeById(id));
    }

    /**
     * 通过id批量删除西安中铁定额发票盘点
     * @param idList
     * @return
     */
    @ApiOperation(value = "通过id批量删除西安中铁定额发票盘点", notes = "通过id批量删除西安中铁定额发票盘点")
    @SysLog("通过id批量删除西安中铁定额发票盘点")
    @PostMapping("/batchDelete")
    @PreAuthorize("@pms.hasPermission('stm_swstinvoicexaztcheck_batch_del')")
    public R batchRemoveByIds(@RequestBody List<Integer> idList) {
        idList.forEach(swStInvoiceXaztCheckService::removeById);
        return R.ok();
    }

    /**
     * 通过日期查询前一月盘点数据
     *
     * @param checkTime
     * @return R
     */
    @ApiOperation(value = "通过日期查询前一月盘点数据", notes = "通过日期查询前一月盘点数据")
    @GetMapping("/getPreviousMonthInvoiceXaztCheck")
    public R getPreviousMonthInvoiceXaztCheck(String checkTime) {
        return R.ok(swStInvoiceXaztCheckService.getPreviousMonthInvoiceXaztCheck(checkTime, 0));
    }

    /**
     * 通过日期查询当月西安中铁定额发票盘点数据
     *
     * @param checkTime
     * @return R
     */
    @ApiOperation(value = "通过日期查询当月备用金盘点数据", notes = "通过日期查询当月备用金盘点数据")
    @GetMapping("/getInvoiceXaztCheck")
    public R getTicketCheck(String checkTime) {
        PigxUser user = SecurityUtils.getUser();
        LambdaQueryWrapper<SwStInvoiceXaztCheck> queryWrapper = Wrappers.<SwStInvoiceXaztCheck>lambdaQuery()
                .eq(SwStInvoiceXaztCheck::getLineCode, user.getLineCode())
                .eq(SwStInvoiceXaztCheck::getStationCode, user.getStationCode())
                .eq(SwStInvoiceXaztCheck::getDelFlag, "0")
                .eq(SwStInvoiceXaztCheck::getStatisticsDate, checkTime)
                .notIn(SwStInvoiceXaztCheck::getCheckStatus,2,4,6);
        return R.ok(swStInvoiceXaztCheckService.getMap(queryWrapper));
    }

    @ApiOperation(value = "通过日期查询当月备用金盘点数据", notes = "通过日期查询当月备用金盘点数据")
    @GetMapping("/getInvoiceXaztCheckEdit")
    public R getInvoiceXaztCheckEdit(Integer id,String checkTime) {
        PigxUser user = SecurityUtils.getUser();
        LambdaQueryWrapper<SwStInvoiceXaztCheck> queryWrapper = Wrappers.<SwStInvoiceXaztCheck>lambdaQuery()
                .eq(SwStInvoiceXaztCheck::getLineCode, user.getLineCode())
                .eq(SwStInvoiceXaztCheck::getStationCode, user.getStationCode())
                .eq(SwStInvoiceXaztCheck::getDelFlag, "0")
                .eq(SwStInvoiceXaztCheck::getStatisticsDate, checkTime)
//                .notIn(SwStInvoiceXaztCheck::getCheckStatus,2,4,6)
                .ne(SwStInvoiceXaztCheck::getId, id);
        return R.ok(swStInvoiceXaztCheckService.getMap(queryWrapper));
    }

    /**
     * 新增或修改西安中铁定额发票盘点
     *
     * @param swStInvoiceXaztCheck 西安中铁定额发票盘点
     * @return R
     */
    @ApiOperation(value = "新增或修改西安中铁定额发票盘点", notes = "新增或修改西安中铁定额发票盘点")
    @SysLog("新增或修改西安中铁定额发票盘点")
    @PostMapping("saveOrUpdate")
    @PreAuthorize("@pms.hasPermission('stm_swstinvoicexaztcheck_add_or_update')")
    public R saveOrUpdate(@RequestBody SwStInvoiceXaztCheck swStInvoiceXaztCheck) {
        return R.ok(swStInvoiceXaztCheckService.saveOrUpdateInvoiceXaztCheck(swStInvoiceXaztCheck));
    }

    /**
     * 西安中铁定额发票盘点数据批量提交
     */
    @ApiOperation(value = "西安中铁定额发票盘点数据批量提交", notes = "西安中铁定额发票盘点数据批量提交")
    @PutMapping("/modify/submit/status")
    @PreAuthorize("@pms.hasPermission('stm_swstinvoicexaztcheck_batch_submit')")
    public R updateSubmitStatus(@RequestParam("ids") List<Integer> ids, @RequestParam("status") String status) {
        return R.ok(swStInvoiceXaztCheckService.updateApprovalStatus(ids, status, null));
    }

    /**
     * 西安中铁定额发票盘点数据批量审核
     */
    @ApiOperation(value = "西安中铁定额发票盘点数据批量审核", notes = "西安中铁定额发票盘点数据批量审核")
    @PutMapping("/modify/approval/status")
    @PreAuthorize("@pms.hasPermission('stm_swstinvoicexaztcheck_batch_approval')")
    public R updateApprovalStatus(@RequestParam("ids") List<Integer> ids, @RequestParam("status") String status) {
        return R.ok(swStInvoiceXaztCheckService.updateApprovalStatus(ids, status, InvoiceChechAuditTypeEnum.AUDIT_STATION.getCode()));
    }

    /**
     * 西安中铁定额发票盘点数据批量驳回
     */
    @ApiOperation(value = "西安中铁定额发票盘点数据批量驳回", notes = "西安中铁定额发票盘点数据批量驳回")
    @PutMapping("/modify/reject/status")
    @PreAuthorize("@pms.hasPermission('stm_swstinvoicexaztcheck_batch_reject')")
    public R updateRejectStatus(@RequestParam("ids") List<Integer> ids, @RequestParam("status") String status) {
        return R.ok(swStInvoiceXaztCheckService.updateApprovalStatus(ids, status, null));
    }

    /**
     * 西安中铁定额发票盘点数据车间票务专业审核
     */
    @ApiOperation(value = "西安中铁定额发票盘点数据车间票务专业审核", notes = "西安中铁定额发票盘点数据车间票务专业审核")
    @PutMapping("/modify/workshopApproval/status")
    @PreAuthorize("@pms.hasPermission('stm_swstinvoicexaztcheck_workshop_approval')")
    public R updateWorkshopApproval(@RequestParam("ids") List<Integer> ids, @RequestParam("status") String status) {
        return R.ok(swStInvoiceXaztCheckService.updateApprovalStatus(ids, status, InvoiceChechAuditTypeEnum.AUDIT_WORKSHOP.getCode()));
    }

    /**
     * 西安中铁定额发票盘点数据车间票务专业驳回
     */
    @ApiOperation(value = "西安中铁定额发票盘点数据车间票务专业驳回", notes = "西安中铁定额发票盘点数据车间票务专业驳回")
    @PutMapping("/modify/workshopReject/status")
    @PreAuthorize("@pms.hasPermission('stm_swstinvoicexaztcheck_workshop_reject')")
    public R updateWorkshopReject(@RequestParam("ids") List<Integer> ids, @RequestParam("status") String status) {
        return R.ok(swStInvoiceXaztCheckService.updateApprovalStatus(ids, status, null));
    }

    /**
     * 西安中铁定额发票盘点数据部门票务专业审核
     */
    @ApiOperation(value = "西安中铁定额发票盘点数据部门票务专业审核", notes = "西安中铁定额发票盘点数据部门票务专业审核")
    @PutMapping("/modify/departmentApproval/status")
    @PreAuthorize("@pms.hasPermission('stm_swstinvoicexaztcheck_department_approval')")
    public R updateDepartmentApproval(@RequestParam("ids") List<Integer> ids, @RequestParam("status") String status) {
        return R.ok(swStInvoiceXaztCheckService.updateApprovalStatus(ids, status, InvoiceChechAuditTypeEnum.AUDIT_DEPT.getCode()));
    }

    /**
     * 西安中铁定额发票盘点数据部门票务专业驳回
     */
    @ApiOperation(value = "西安中铁定额发票盘点数据部门票务专业驳回", notes = "西安中铁定额发票盘点数据部门票务专业驳回")
    @PutMapping("/modify/departmentReject/status")
    @PreAuthorize("@pms.hasPermission('stm_swstinvoicexaztcheck_department_reject')")
    public R updateDepartmentReject(@RequestParam("ids") List<Integer> ids, @RequestParam("status") String status) {
        return R.ok(swStInvoiceXaztCheckService.updateApprovalStatus(ids, status, null));
    }

    /**
     * 车站导出西安中铁定额发票盘点
     * @param response
     */
    @PostMapping("/exportInvoiceXaztCheckForStation")
    @SysLog("车站导出西安中铁定额发票盘点")
    public void exportInvoiceXaztCheckForStation(@RequestBody Long id, HttpServletResponse response) {
        swStInvoiceXaztCheckService.exportInvoiceXaztCheckForStation(id, response);
    }

	  /**
     * 车站导出西安中铁定额发票盘点
     * @param response
     */
    @PostMapping("/exportInvoiceXaztCheckForStationAll")
    //@SysLog("车站导出西安中铁定额发票盘点")
    public void exportInvoiceXaztCheckForStationAll(@RequestBody String checkTime, HttpServletResponse response) {
        swStInvoiceXaztCheckService.exportInvoiceXaztCheckForStationAll(checkTime, response);
    }
}
